
package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsCategory;
import com.qf.service.AdminService;
import com.qf.service.BrandService;
import com.qf.service.CategoryService;
import com.qf.util.ResponseUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: wokepase1
 *
 * @author: 强力
 * time: 2021/9/15 16:25
 * description:
 */
@RestController
@RequestMapping("/brand")
@CrossOrigin("*")
public class BrandController{
@Autowired
private AdminService adminService;
@Autowired
    private BrandService brandService;
@Autowired
private CategoryService categoryService;
@RequestMapping("/list")
    public Object list(Integer page, Integer limit,Integer id,String name,String sort,String order){
    IPage<DtsBrand> brandIPage=brandService.findByPage(page,limit,id,name,sort,order);

    Map<String,Object>data= new HashMap<>();
    data.put("total",brandIPage.getTotal());
    data.put("items",brandIPage.getRecords());
    return ResponseUtil.ok(data);
}

@RequestMapping("/catAndAdmin")
    public Object catAndAdmin(){
    Map<String,Object> data=new HashMap();
        List<Map<String,Object>> adminList =new ArrayList<>();

        List<DtsAdmin> admins=adminService.findAdminlist();
    if (admins != null) {
        for (DtsAdmin admin : admins) {
            Map<String,Object> temp=new HashMap<>();
            temp.put("value",admin.getId());
            temp.put("label",admin.getUsername());
            adminList.add(temp);

        }
    }


        List<Map<String,Object>> categoryList=new ArrayList<>();

        List<DtsCategory> categories= categoryService.findcategoryList();
    if (categories != null) {
        for (DtsCategory category : categories) {
            Map<String,Object> temp1=new HashMap<>();
            temp1.put("value",category.getId());
            temp1.put("label",category.getName());
            categoryList.add(temp1);

        }
    }

         data.put("adminList",adminList);
         data.put("categoryList",categoryList);

return  ResponseUtil.ok(data);
}
}
